package com.mt.channel.service.impl;

import java.util.List;
import java.util.Map;


import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.mt.channel.api.service.IChannelRoleService;
import com.mt.channel.entity.ChannelRoleEntity;
import com.mt.channel.service.model.ChannelRoleServiceModel;
import com.mt.common.PagerInfo;
import com.mt.common.ServiceResult;
import com.mt.common.constants.BaseErrorConstants;
import org.springframework.stereotype.Service;

@Service
public class ChannelRoleServiceImpl implements IChannelRoleService {

	private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(ChannelRoleServiceImpl.class);

	@Autowired
	private ChannelRoleServiceModel channelRoleServiceModel;

	public ServiceResult<ChannelRoleEntity> findInfo(Map<String, Object> params) {
		// 查询用户信息
		ServiceResult<ChannelRoleEntity> result = null;
		// 该参数标识前段是否需要权限数据
		try {
			result = channelRoleServiceModel.selectInfo(params);
		} catch (Exception e) {
			LOGGER.error("[ChannelRoleServiceImpl][findInfo]：query findInfo occur exception", e);
			result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "查询详情错误");
		}
		return result;
	}

	public ServiceResult<List<ChannelRoleEntity>> findList(Map<String, Object> params, PagerInfo<?> pagerInfo) {
		ServiceResult<List<ChannelRoleEntity>> result = new ServiceResult<List<ChannelRoleEntity>>();
		try {
			result = channelRoleServiceModel.selectList(params, pagerInfo);
		} catch (Exception e) {
			LOGGER.error("[ChannelRoleServiceImpl][findList]：query findList occur exception", e);
			result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "查询列表错误");
		}

		return result;
	}

	public ServiceResult<Integer> doInsert(ChannelRoleEntity channelRoleEntity) {
		ServiceResult<Integer> result = new ServiceResult<Integer>();
		try {
			result = channelRoleServiceModel.insert(channelRoleEntity);
		} catch (Exception e) {
			LOGGER.error("[ChannelRoleServiceImpl][doInsert]：query doInsert occur exception", e);
			result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "创建信息错误");
		}
		return result;
	}

	public ServiceResult<Integer> doUpdateRelate(ChannelRoleEntity channelRoleEntity) {
		ServiceResult<Integer> result = new ServiceResult<Integer>();
		try {
			result = channelRoleServiceModel.updateRelate(channelRoleEntity);
		} catch (Exception e) {
			LOGGER.error("[ChannelRoleServiceImpl][doUpdate]：query doUpdate occur exception", e);
			result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "编辑信息错误");
		}
		return result;
	}

	public ServiceResult<Integer> doDeleteById(Integer channelRoleId) {
		ServiceResult<Integer> result = new ServiceResult<Integer>();
		try {
			result = channelRoleServiceModel.doDeleteByPrimaryKey(channelRoleId);
		} catch (Exception e) {
			LOGGER.error("[ChannelServiceImpl][doDeleteById]：query doDeleteById occur exception", e);
			result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "删除信息错误");
		}
		return result;
	}

	public ServiceResult<Integer> doDeleteById(ChannelRoleEntity channelRoleEntity) {
		ServiceResult<Integer> result = new ServiceResult<Integer>();
		try {
			result = channelRoleServiceModel.deleteByPrimaryKey(channelRoleEntity);
		} catch (Exception e) {
			LOGGER.error("[ChannelRoleServiceImpl][doDeleteById]：query doDeleteById occur exception", e);
			result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "删除信息错误");
		}
		return result;
	}

	public ServiceResult<Integer> doUpdate(ChannelRoleEntity channelRoleEntity) {
		ServiceResult<Integer> result = new ServiceResult<Integer>();
		try {
			result = channelRoleServiceModel.updateByPrimaryKeySelective(channelRoleEntity);
		} catch (Exception e) {
			LOGGER.error("[ChannelServiceImpl][doUpdate]：query doUpdate occur exception", e);
			result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "更新信息错误.");
		}
		return result;
	}

}
